package HomeWork;

import Domain.Avengers;

import java.util.ArrayList;

/*
1定义一个Avengers类

  	 1)属性: 编号id ( int类型 ) ，姓名name（String类型），性别sex （String类型）

  	2)方法：空参满参构造 set、get方法   

1. 在测试类中创建6个对象（对象数据如下），依次将Avengers对象存入集合。   
   1,"钢铁侠","男"
   2,"美国队长","男"     

   3,"黑寡妇","女"    

      4,"绿巨人","男"

     5,"雷神","男"     

     6,"星云","女"

1. 遍历集合删除其中性别为男且姓名长度大于等于3的元素，将剩余的元素数据打印在控制台。

 */
public class Test2 {
    public static void main(String[] args) {
        ArrayList<Avengers> list = new ArrayList<>();

        list.add(new Avengers(1,"钢铁侠","男"));
        list.add(new Avengers(2,"美国队长","男"));
        list.add(new Avengers(3,"黑寡妇","女"));
        list.add(new Avengers(4,"绿巨人","男"));
        list.add(new Avengers(5,"雷神","男" ));
        list.add(new Avengers(6,"星云","女"));

        for (int i = 0; i < list.size(); i++) {
            Avengers avg = list.get(i);
            if("男".equals(avg.getSex())){
                StringBuilder sb = new StringBuilder(avg.getName());
                if(sb.length() >= 3){
                    list.remove(i);
                    i--;
                }
            }
        }

        for (int i = 0; i < list.size(); i++) {
            Avengers avg = list.get(i);
            System.out.println(avg.getName());
        }

    }
}
